<?php
class DFData {
	var $clientname ; 
	var $clientid ; 
	var $datetime ;
	var $count ;
	var $dflist ;
	
	function DFData($params)
	{
		$this->clientname = $params["clientname"] ;
		$this->clientid = $params["clientid"] ;
		$this->dflist = array();
		$this->datetime = date("Y-m-d H:i:s") ;
		$this->count = 0 ;
	}
	
	function decodeDF($dfline)
	{
		$df = array() ;
		$dfline = ereg_replace(" +"," ",$dfline);
		$dfline = ereg_replace("\n","",$dfline);
		
		$arr = explode(" ",$dfline);
		/*data post processing*/
		$arr[4] = ereg_replace("%","",$arr[4]);
	
		$this->dflist[$this->count] = $arr ;
		$this->count++ ;
	}
	
	function show()
	{
		echo "<br>id=".$this->clientid ;
		echo " name :".$this->clientname ;
		echo "<br>time :".$this->datetime ;
		echo "<table border=1>";
		foreach ($this->dflist as $d) {
			echo "<tr>";
			echo "<td>".$d[0]."</td>" ;
			echo "<td>".$d[1]."</td>" ;
			echo "<td>".$d[2]."</td>" ;
			echo "<td>".$d[3]."</td>" ;
			echo "<td>".$d[4]."</td>" ;
			echo "<td>".$d[5]."</td>" ;
			echo "</tr>";
		}
		echo "</table>" ;
	}
	
	function makeInsertQuery()
	{
		$insertQuery = "INSERT INTO `history` 	(`id`,`client_id`,`datetime`,`status`,`device`,`size`,`used`,`available`,`usedPercent`,`mounted`)\n  VALUES  ";
		
		foreach($this->dflist as $df)
		{
			$insertQuery =$insertQuery . "(NULL,'$this->clientid','$this->datetime','up','$df[0]','$df[1]','$df[2]','$df[3]','$df[4]','$df[5]'),\n";
		}
		$pos = strrpos($insertQuery,",");
		$insertQuery[$pos] = ";"; 
		return $insertQuery	;	
	}
	
}
/*
$df = new DFData("2","ggcook.no-ip.info");
$df->decodeDF("/dev/hda1               124427     15728    102275  14% /boot");
$df->decodeDF("/dev/hda2 19228388 2142384 16109172 92% /");

$df->show();
echo $df->makeInsertQuery();
*/	
?>